package com.itkun.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itkun.damain.Book;
import com.itkun.dao.BookDao;
import com.itkun.service.IBookService;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class BookServiceImpl extends ServiceImpl<BookDao, Book> implements IBookService {

    @Autowired
    private BookDao bookDao;

    @Override
    public IPage<Book> getPage(int currentPage, int pageSize, Book book) {
        LambdaQueryWrapper<Book> lqw = new LambdaQueryWrapper<>();
        lqw.like(Strings.isNotEmpty(book.getUname()),Book::getUname,book.getUname());
        lqw.like(Strings.isNotEmpty(book.getUpassword()),Book::getUpassword,book.getUpassword());
        lqw.like(Strings.isNotEmpty(book.getUemail()),Book::getUemail,book.getUemail());

        IPage page = new Page(currentPage,pageSize);
        bookDao.selectPage(page,lqw);
        return page;
    }
    @Override
    public IPage<Book> getPage(int currentPage, int pageSize) {

        IPage page = new Page(currentPage,pageSize);
        bookDao.selectPage(page,null);
        return page;
    }

//    @Override
//    public IPage<Book> getPage(int currentPage, int pageSize) {
//        return null;
//    }
}
